/** 
 * @Title:  UpdateTypeDialog.java 
 * @author:  Abtswiath丶lxy
 * @data:  2016年6月14日 下午5:21:16 <创建时间>
 * 
 * @history：<以下是历史记录>
 *
 * @modifier: <修改人>
 * @modify date: 2016年6月14日 下午5:21:16 <修改时间>
 * @log: <修改内容>
 *
 * @modifier: <修改人>
 * @modify date: 2016年6月14日 下午5:21:16 <修改时间>
 * @log: <修改内容>
 */
package com.sunmi.usercenter.ui.component;

import java.util.List;

import com.sunmi.usercenter.R;
import com.sunmi.usercenter.bean.ShopType;
import com.sunmi.usercenter.ui.adapter.DialogListViewAdapter;

import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

/** 
 * TODO<请描述这个类是干什么的> 
 * @author Abtswiath丶lxy
 * @versionCode 1 <每次修改提交前+1>
 */
public class UpdateTypeDialog extends DialogFragment {

	private Context mContext;
	private LoadingDialog mLoadingDialog;

/*	public UpdateTypeDialog(Context context, int theme) {
		super(context, theme);
		this.mContext = context;
	}

	public UpdateTypeDialog(Context context) {
		super(context);
		this.mContext = context;
	}*/
	/* (non-Javadoc)
	 * @see android.support.v4.app.DialogFragment#onActivityCreated(android.os.Bundle)
	 */
	
	
	@Override
	public void onActivityCreated(Bundle arg0) {
		super.onActivityCreated(arg0);
		ListView listView = (ListView)mView.findViewById(R.id.listview);
		TextView cancel = (TextView) mView.findViewById(R.id.cancel);
		DialogListViewAdapter adapter = new DialogListViewAdapter(getActivity(), types);
		listView.setAdapter(adapter);
		mLoadingDialog = LoadingDialog.createDialog(getActivity(), getString(R.string.saveing));
		listView.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
				mLoadingDialog.show();
				linstener.click(types.get(position).gettId());
			}
		});
		cancel.setOnClickListener(new android.view.View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				linstener.cancel();
			}
		});
	}
	
	private  List<ShopType> types;
	private updateTypeLinstener linstener;
	public UpdateTypeDialog(final List<ShopType> types,final updateTypeLinstener linstener) {
		super();
		this.linstener = linstener;
		this.types = types;
	}

	private View mView;
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		super.onCreateView(inflater, container, savedInstanceState);
		getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE);
		getDialog().getWindow().getAttributes().gravity = Gravity.CENTER;
		getDialog().setCanceledOnTouchOutside(true);
		getDialog().setCancelable(false);
		return mView = inflater.inflate(R.layout.dialog_shop_type, container);
	}

	public interface updateTypeLinstener {
		public void click(String tid);
		public void cancel();
	}

	@Override
	public void dismiss() {
		super.dismiss();
		if(mLoadingDialog!=null){
			mLoadingDialog.dismiss();
		}
		if(mContext!=null){
			mContext = null;
		}
		
		
	}
	
	
}
